using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class GM : MonoBehaviour
{
    [HideInInspector]
    public int enemycount = 10;

    public List<AudioSource> audios;
    public Text goldText;

    public Transform ShopPlane;
    public Transform SettingPlane;
    public Transform IllustrationPlane;

    public Transform GameOverPlane;
    public Transform GameCompletePlane;

    public Sprite onMusic;
    public Sprite offnMusic;

    public Image MusicBtn;

    static bool music = true;

    private void Start()
    {
        Time.timeScale = 1;
        if(music)
        {
            foreach (var temp in audios) temp.volume = 1;
        }
        else
        {
            foreach (var temp in audios) temp.volume = 0;
        }
        //Data.saveData();
        Data.loadData();
        updataGold();
        
    }

    void clickedBtn()
    {
        GetComponent<AudioSource>().Play();
    }

    public void clickedStartBtn()
    {
        clickedBtn();
        Data.saveData();
        SceneManager.LoadScene(1);
    }

    public void clickedExitBtn()
    {
        clickedBtn();
        Data.saveData();
        Application.Quit();
    }

    public void clickedSettingBtn()
    {
        clickedBtn();
        SettingPlane.gameObject.SetActive(true);
    }

    public void clickedIllustrationBtn()
    {
        clickedBtn();
        IllustrationPlane.gameObject.SetActive(true);
    }

    public void clickedShopBtn()
    {
        clickedBtn();
        ShopPlane.gameObject.SetActive(true);
    }

    public void clickedBackBtn()
    {
        
        IllustrationPlane.gameObject.SetActive(false);
        ShopPlane.gameObject.SetActive(false);
        SettingPlane.gameObject.SetActive(false);
        clickedBtn();
    }

    public void clickedMusicBtn()
    {
        
        music = !music;
        if (music)
        {
            MusicBtn.sprite = onMusic;
            foreach (var temp in audios) temp.volume = 1;
        }
        else
        {
            MusicBtn.sprite = offnMusic;
            foreach (var temp in audios) temp.volume = 0;
        }
        clickedBtn();
    }

    public void clickedRestartBtn()
    {
        clickedBtn();
        Data.saveData();
        SceneManager.LoadScene(1);
    }

    public void clickedReturnMenuBtn()
    {
        clickedBtn();
        Data.saveData();
        SceneManager.LoadScene(0);
    }

    public void updataGold()
    {
        goldText.text = ""+ Data.gold;
    }

    public void destoryEnemy()
    {
        enemycount--;
        if(enemycount==0)
        {
            Time.timeScale = 0;
            GameCompletePlane.gameObject.SetActive(true);
        }
    }

}
